# Works with 3.11 and tested through 3.21
cmake_minimum_required(VERSION 3.12...3.21)

# Project name and a few useful settings. Other commands can pick up the results
project(
  Logger
  VERSION 0.0.1
  DESCRIPTION "An Logger based on spdlog"
  LANGUAGES CXX)

# set project build type
if(NOT CMAKE_BUILD_TYPE)
    set(CMAKE_BUILD_TYPE Release CACHE STRING "Build type" FORCE)
endif()
message(STATUS "Build type set to ${CMAKE_BUILD_TYPE}")

# Only do these if this is the main project, and not if it is included through add_subdirectory
if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)

  # Optionally set things like CMAKE_CXX_STANDARD, CMAKE_POSITION_INDEPENDENT_CODE here
  set(CMAKE_CXX_STANDARD 11 CACHE STRING "The C++ standard to use")
  set(CMAKE_CXX_STANDARD_REQUIRED ON)

  # Let's ensure -std=c++xx instead of -std=g++xx
  set(CMAKE_CXX_EXTENSIONS OFF)

  # Let's nicely support folders in IDEs
  set_property(GLOBAL PROPERTY USE_FOLDERS ON)

  # Testing only available if this is the main app
  # Note this needs to be done in the main CMakeLists
  # since it calls enable_testing, which must be in the
  # main CMakeLists.

  # Docs only available if this is the main app

endif()

# FetchContent added in CMake 3.11, downloads during the configure step
# FetchContent_MakeAvailable was not added until CMake 3.14; use our shim
if(NOT spdlog_FOUND)
    include(FetchContent)
    FetchContent_Declare(spdlog
            GIT_REPOSITORY https://gitee.com/taoweitao/spdlog.git
            GIT_TAG v1.x
            SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/extern/spdlog)
    FetchContent_MakeAvailable(spdlog)
endif()

# Accumulator library
# This is header only, so could be replaced with git submodules or FetchContent

# Adds Boost::boost

# The compiled library code is here
#add_subdirectory(extern/spdlog)
add_subdirectory(src)


# Testing only available if this is the main app
# Emergency override MODERN_CMAKE_BUILD_TESTING provided as well

option(ENABLE_UNIT_TESTS "Enable unit tests" ON)
message(STATUS "Enable testing: ${ENABLE_UNIT_TESTS}")
if(ENABLE_UNIT_TESTS)
    # all the remaining CMake code will be placed here
    add_subdirectory(tests)
endif()



